import "@/assets/css/global.less";
import ResponsiveLayout from "@/layouts/admin";
import i18n from "@/locales/i18n";
import useTotalStore from "@/store";
import useStore from "@/store/configStore";
import { ConfigProvider, type ConfigProviderProps } from "antd";
import { useEffect } from "react";
import { Outlet, useLocation } from "umi";
import "./index.less";
type Locale = ConfigProviderProps["locale"];

const locales = i18n.store.data;
export default function Layout() {
  const storeTotal = useTotalStore();

  console.log(storeTotal, "storeTotal");
  const { lang, login, logoutFail, logout, isLoggedIn } = useStore();

  const location = useLocation();
  // 获取查询参数
  const queryParams = new URLSearchParams(location.search);
  const type = queryParams.get("type");
  // console.log(lang, "lang");

  useEffect(() => {
    console.log("--------------------------------------");
    i18n.changeLanguage(lang);
    // dayjs.locale(lang === 'hk' ? 'zh-hk' : lang);
    // i18nChangeLanguage(lang === 'cn' ? 'zh-CN' : lang);
  }, [lang]);

  useEffect(() => {
    // 根据查询参数的值调用相应的方法
    if (isLoggedIn === "true") {
      login("John Doe");
    } else if (type === "2") {
      logout();
    } else if (type === "3") {
      logoutFail();
    }
  }, [location.search, login, isLoggedIn]);

  return (
    <>
      <ConfigProvider
        locale={locales[lang] as unknown as Locale}
        input={{ autoComplete: "off" }}
      >
        {/* <LayoutContainer>
          <Headers />
          <Content>
            <Outlet />
          </Content>
          <Footer />
        </LayoutContainer> */}
        <ResponsiveLayout>
          <Outlet />
        </ResponsiveLayout>
      </ConfigProvider>
    </>
  );
}
